﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class layout1 : System.Web.UI.UserControl
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SqlCommand cmdProduct;
                SqlDataReader dtrProduct;
                conn.Open();

                cmdProduct = new SqlCommand("SELECT * FROM Products p, Users u WHERE p.u_id=u.u_id", conn);
                dtrProduct = cmdProduct.ExecuteReader();

                ItemList.DataSource = dtrProduct;
                ItemList.DataBind();

                dtrProduct.Close();
                conn.Close();
            }
            catch (SqlException ex)
            {
                MessageBox(ex.Message);
            }
        }

        public string getBgColor()
        {
            SqlCommand cmdSearch;
            SqlDataReader dtrSearch;
            conn.Open();

            cmdSearch = new SqlCommand("Select bgColor From Virtual_Shop Where v_id=@id", conn);
            cmdSearch.Parameters.AddWithValue("@id", 1);
            dtrSearch = cmdSearch.ExecuteReader();

            dtrSearch.Read();
            String s = dtrSearch["bgColor"].ToString();

            dtrSearch.Close();
            conn.Close();

            return s;
        }

        public string getFont()
        {
            SqlCommand cmdSearch;
            SqlDataReader dtrSearch;
            conn.Open();

            cmdSearch = new SqlCommand("Select font From Virtual_Shop Where v_id=@id", conn);
            cmdSearch.Parameters.AddWithValue("@id", 1);
            dtrSearch = cmdSearch.ExecuteReader();

            dtrSearch.Read();
            String s = dtrSearch["font"].ToString();

            dtrSearch.Close();
            conn.Close();

            return s;
        }

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }
    }
}